<?php $this->load->view('provider/template/_begin') ?>
<?php $this->load->view('provider/promotion/_script') ?>
<form action="<?php echo site_url('provider/promotion/update'); ?>" id="form_promotion"
      method="post" enctype="multipart/form-data">
  <input type="hidden" name="lat" id="lat" value="<?php echo empty($obj["lat"]) ? "" : $obj["lat"] ?>"/>
  <input type="hidden" name="lng" id="lng" value="<?php echo empty($obj["lng"]) ? "" : $obj["lng"] ?>"/>
  <input type="hidden" name="id" id="id" value="<?php echo empty($obj["id"]) ? "0" : $obj["id"] ?>"/>
  <div class="form1">
    <table class="table1">
      <tr>
        <td class="text4">Title:<span>*</span></td>
        <td>
          <input type="text" name="title" id="title" value="<?php echo empty($obj["title"]) ? "" : $obj["title"] ?>" 
                 class="input1 validate[required]"/>
        </td>
        <td class="text4">Code:<span>*</span></td>
        <td><input type="text" name="code" id="code" value="<?php echo empty($obj["code"]) ? "" : $obj["code"] ?>" 
                   class="input1 validate[required]"/></td>
      </tr>
      <tr>
        <td class="text4">Categories:<span>*</span></td>
        <td>
          <select size="7" class="select_multiple validate[required]" style="height: auto" 
                  id="category" name="category[]" multiple="multiple">
            <?php foreach ($categories as $ref) { ?>
              <option value="<?php echo $ref["id"] ?>"
                      <?php echo!empty($obj["category"]) && in_array($ref["id"], $obj["category"]) ? 'selected="selected"' : '' ?>>
                        <?php echo $this->category_model->to_string($ref) ?>
              </option>
            <?php } ?>
          </select>
        </td> 
        <td class="text4">Related promotion:</td>
        <td>
          <select size="7" class="select_multiple" style="height: auto" 
                  id="related_promotion" name="promotion2_id[]" multiple="multiple">
            <?php foreach ($relate_promotions as $ref) { ?>
              <option value="<?php echo $ref["id"] ?>"
                      <?php echo!empty($obj["promotion2_id"]) && in_array($ref['id'], $obj['promotion2_id']) ? 'selected="selected"' : '' ?>>
                => <?php echo $this->promotion_model->to_string($ref) ?>
              </option>
            <?php } ?>
          </select>
        </td>
      </tr>
      <tr>
        <td class="text4">Description:<span>*</span></td>
        <td colspan="3">
          <textarea id="description" class="textarea1 input2 validate[required]" name="description"><?php echo empty($obj["description"]) ? "" : $obj["description"] ?></textarea>
        </td>
      </tr>
      <tr>
        <td class="text4">Start date:<span>*</span></td>
        <td><input type="text" name="start_date" class="input1 validate[required]" id="start_date"
                   value="<?php echo empty($obj["start_date"]) ? date($this->setting_model->item('date_format')) : $obj["start_date"] ?>"/></td>
        <td class="text4">Total promotion:<span>*</span></td>
        <td>
          <input id="max_download" type="text" name="max_download" class="input1 number validate[required]"
                 value="<?php echo empty($obj["max_download"]) ? "" : $obj["max_download"] ?>" />
        </td>
      </tr>
      <tr>
        <td class="text4">Expire date:<span>*</span></td>
        <td><input type="text" name="end_date" class="input1 validate[required]" id="end_date"
                   value="<?php echo empty($obj["end_date"]) ? date($this->setting_model->item('date_format')) : $obj["end_date"] ?>"/></td>        
        <td class="text4">Limit per person:<span>*</span></td>
        <td><input id="max_per_person" type="text" name="max_per_person" class="input1 number validate[required]"
                   value="<?php echo empty($obj["max_per_person"]) ? "" : $obj["max_per_person"] ?>" /></td>
      </tr>
      <tr>
        <td class="text4">Select country:<span>*</span></td>
        <td>
          <select class="select1 validate[required]" name="country_id" id="country_id">
            <option selected="" value=""><?php echo $this->lang->line('label.country.select') ?></option>
            <?php
            $ref_objs = $this->country_model->get_all();
            foreach ($ref_objs as $ref) {
              ?>
              <option value="<?php echo $ref["id"] ?>"
                      <?php echo empty($obj["country_id"]) || $obj["country_id"] != $ref["id"] ? "" : 'selected="selected"' ?>>
                        <?php echo $this->country_model->to_string($ref) ?>
              </option>
            <?php } ?>
          </select>
        </td>
        <td class="text4">Support channel:<span>*</span></td>
        <td>
          <select id="support_channel" name="support_channel" class="select1 validate[required]" >
            <?php
            $support_channel = array(
                PROMOTION_CHANNEL_ALL => $this->lang->line('label.promotion.support_channel.all'),
                PROMOTION_CHANNEL_EMAIL => $this->lang->line('label.promotion.support_channel.email'),
                PROMOTION_CHANNEL_SMS => $this->lang->line('label.promotion.support_channel.sms'));
            foreach ($support_channel as $value => $label) {
              ?>
              <option value="<?php echo $value ?>"
                      <?php echo empty($obj["support_channel"]) || $obj["support_channel"] != $value ? "" : 'selected="selected"' ?>>
                        <?php echo $label ?>
              </option>
            <?php } ?>
          </select>
        </td>        
      </tr>
      <tr>
        <td class="text4">Select state:<span>*</span></td>
        <td>
          <select class="select1 validate[required]" name="state_id" id="state_id">
            <option value=""><?php echo $this->lang->line('label.state.select') ?></option>
          </select>
        </td>
        <td class="text4">Support encode:<span>*</span></td>
        <td>
          <select id="support_encode" name="support_encode" class="select1 validate[required]">
            <?php
            $support_encode = array(
                PROMOTION_ENCODE_ALL => $this->lang->line('label.promotion.support_encode.all'),
                PROMOTION_ENCODE_BARCODE => $this->lang->line('label.promotion.support_encode.barcode'),
                PROMOTION_ENCODE_TEXT => $this->lang->line('label.promotion.support_encode.text'));
            foreach ($support_encode as $value => $label) {
              ?>
              <option value="<?php echo $value ?>"
                      <?php echo empty($obj["support_encode"]) || $obj["support_encode"] != $value ? "" : 'selected="selected"' ?>>
                        <?php echo $label ?>
              </option>
            <?php } ?>
          </select>
        </td>
        
      </tr>
      <tr>
        <td class="text4">Select city:<span>*</span></td>
        <td>
          <select class="select1 validate[required]" name="city_id" id="city_id">
            <option selected="" value=""><?php echo $this->lang->line('label.city.select') ?></option>
          </select>
        </td>                
      </tr>
      <tr>
        <td class="text4">Location:</td>
        <td colspan="3">
          <div id="map" class="input2" style="height: 200px"></div>
        </td>
      </tr>
      <tr>
        <td class="text4">Image(s):</td>
        <td colspan="3">
          <div style="float: left;width: 100%;padding-bottom: 5px;">
            <?php foreach ($obj['images'] as $image) { ?>
            <div style="margin: 10px;width: 150px;height: 150px; float: left;position: relative">
                <input type="hidden" name="images_id[]" value="<?php echo $image['id'] ?>"/>                
                <img width="150px" alt="" style="max-height: 150px;"
                     src="<?php echo site_url('admin/promotion_media/preview/' . $image['id']) ?>" />
                <img title="<?php echo $this->lang->line('label.promotion.delete') ?>"
                     onclick="if(confirm('Are you sure?')) jQuery(this).parent().remove(); return false;"
                 style="cursor: pointer;position: absolute;z-index: 2;top: 0px;left: 0px; background: #ffffff" 
                 src="<?php echo base_url().APPPATH?>themes/admin/img/icons/delete.png"/>
            </div>
            <?php } ?>
          </div>
          <div style="float: left;width: 100%;padding-bottom: 5px;">
            <input type="file" name="images[]"/>&nbsp;&nbsp;
            <a onclick="add_image(event);return false;" href="#">add</a>
          </div>
        </td>
      </tr>
      <tr>
        <td colspan="4" style="padding-left: 20px">
          <div class="button">
            <div class="button_left"></div>
            <div class="button_bg">
              <a onclick="$('form').submit();return false" href="#">Save promotion</a>
            </div>
            <div class="button_right"></div>
          </div>
          <div class="button">
            <div class="button_left"></div>
            <div class="button_bg">
              <a href="<?php echo site_url('provider/promotion/show/' . $obj['id']) ?>">Cancel</a>
            </div>
            <div class="button_right"></div>
          </div>
        </td>
      </tr>
    </table>
  </div>
</form>
<?php $this->load->view('provider/template/_end') ?>
